var Actions = function () {
    
}
var pro = Actions.prototype;
/**
 * 延时
 * @param target
 * @param data
 */
pro.delayTime = function(node,delayTime,callback) {
    if (node && node.active) {
        let delay = cc.delayTime(delayTime);
        let callFun = cc.callFunc(function () {
            if (!!callback) {
                callback();
            }
        })
        node.runAction(cc.sequence(delay, callFun));
    }
}
/**
 * 移动
 * @param node
 * @param delayTime
 * @param x
 * @param y
 * @param callback
 */
pro.moveTo = function(node,delayTime,x,y,callback) {
    if (node && node.active) {
        let moveTo = cc.moveTo(delayTime,x,y);
        let callFun = cc.callFunc(function () {
            if (!!callback) {
                callback();
            }
        })
        node.runAction(cc.sequence(moveTo, callFun));
    }
}
/**
 * 移动了
 * @param node
 * @param delayTime
 * @param x
 * @param y
 * @param callback
 */
pro.moveBy = function(node,delayTime,x,y,callback) {
    if (node && node.active) {
        let moveBy = cc.moveBy(delayTime,x,y);
        let callFun = cc.callFunc(function () {
            if (!!callback) {
                callback();
            }
        })
        node.runAction(cc.sequence(moveBy, callFun));
    }
}
pro.fadeOut = function(node,delayTime,callback) {
    if (node && node.active) {
        let fadeOut = cc.fadeOut(delayTime);
        let callFun = cc.callFunc(function () {
            if (!!callback) {
                callback();
            }
        })
        node.runAction(cc.sequence(fadeOut, callFun));
    }
}
pro.fadeIn = function(node,delayTime,callback) {
    if (node && node.active) {
        let fadeIn = cc.fadeIn(delayTime);
        let callFun = cc.callFunc(function () {
            if (!!callback) {
                callback();
            }
        })
        node.runAction(cc.sequence(fadeIn, callFun));
    }
}
/**
 * 缩放
 * @param node
 * @param delayTime
 * @param sx
 * @param sy
 * @param callback
 */
pro.scaleTo = function(node,delayTime,sx,sy,callback) {
    if (node && node.active) {
        let scaleTo = cc.scaleTo(delayTime,sx,sy);
        let callFun = cc.callFunc(function () {
            if (!!callback) {
                callback();
            }
        })
        node.runAction(cc.sequence(scaleTo, callFun));
    }
}
/**
 * 缩放
 * @param node
 * @param delayTime
 * @param sx
 * @param sy
 * @param callback
 */
pro.rotateTo = function(node,delayTime,dstAngle,callback) {
    if (node && node.active) {
        let rotateTo = cc.rotateTo(delayTime,dstAngle);
        let callFun = cc.callFunc(function () {
            if (!!callback) {
                callback();
            }
        })
        node.runAction(cc.sequence(rotateTo, callFun));
    }
}
/**
 * 震动
 * @param node
 * @param duration
 */
pro.shake = function(node,duration,callback){
    let x = node.x;
    let y = node.y;
    if (node){
        node.active = true;
        node.runAction(
            cc.repeatForever(
                cc.sequence(
                    cc.moveTo(0.02, cc.v2(x+5, y+7)),
                    cc.moveTo(0.02, cc.v2(x-6, y+7)),
                    cc.moveTo(0.02, cc.v2(x-13, y+3)),
                    cc.moveTo(0.02, cc.v2(x+3, y-6)),
                    cc.moveTo(0.02, cc.v2(x-5, y+5)),
                    cc.moveTo(0.02, cc.v2(x+2, y-8)),
                    cc.moveTo(0.02, cc.v2(x-8, y-10)),
                    cc.moveTo(0.02, cc.v2(x+3, y+10)),
                    cc.moveTo(0.02, cc.v2(x, y))
                )
            )
        );
        setTimeout(() => {
            node.stopAllActions();
            node.setPosition(x,y);
            if (callback){
                callback();
            }
        },duration*1000);
    }
}


pro.moveAndScale = function(node,delayTime,x,y,sx,sy,callback) {
    if (node && node.active) {
        let moveTo = cc.moveTo(delayTime,x,y);
        let scaleTo = cc.scaleTo(delayTime,sx,sy);
        let callFun = cc.callFunc(function () {
            if (!!callback) {
                callback();
            }
        })
        node.runAction(cc.sequence(cc.spawn(moveTo,scaleTo), callFun));
    }
}




module.exports = new Actions();
